home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / GIMP 2.6.8 / gimp-2.6.8-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / drop-shadow.scm < prev    next >
Text File  |  2009-12-15  |  7KB  |  186 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; This program is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ;
  18. ;
  19. ; drop-shadow.scm   version 1.04   1999/12/21
  20. ;
  21. ; CHANGE-LOG:
  22. ; 1.00 - initial release
  23. ; 1.01 - fixed the problem with a remaining copy of the selection
  24. ; 1.02 - some code cleanup, no real changes
  25. ; 1.03 - can't call gimp-edit-fill until layer is added to image!
  26. ;
  27. ;
  28. ; Copyright (C) 1997-1999 Sven Neumann <sven@gimp.org>
  29. ;
  30. ;
  31. ; Adds a drop-shadow of the current selection or alpha-channel.
  32. ;
  33. ; This script is derived from my script add-shadow, which has become
  34. ; obsolete now. Thanks to Andrew Donkin (ard@cs.waikato.ac.nz) for his
  35. ; idea to add alpha-support to add-shadow.
  36.  
  37.  
  38. (define (script-fu-drop-shadow image
  39.                                drawable
  40.                                shadow-transl-x
  41.                                shadow-transl-y
  42.                                shadow-blur
  43.                                shadow-color
  44.                                shadow-opacity
  45.                                allow-resize)
  46.   (let* (
  47.         (shadow-blur (max shadow-blur 0))
  48.         (shadow-opacity (min shadow-opacity 100))
  49.         (shadow-opacity (max shadow-opacity 0))
  50.         (type (car (gimp-drawable-type-with-alpha drawable)))
  51.         (image-width (car (gimp-image-width image)))
  52.         (image-height (car (gimp-image-height image)))
  53.         (from-selection 0)
  54.         (active-selection 0)
  55.         (shadow-layer 0)
  56.         )
  57.  
  58.   (gimp-context-push)
  59.  
  60.   (gimp-image-set-active-layer image drawable)
  61.  
  62.   (gimp-image-undo-group-start image)
  63.  
  64.   (gimp-layer-add-alpha drawable)
  65.   (if (= (car (gimp-selection-is-empty image)) TRUE)
  66.       (begin
  67.         (gimp-selection-layer-alpha drawable)
  68.         (set! from-selection FALSE))
  69.       (begin
  70.         (set! from-selection TRUE)
  71.         (set! active-selection (car (gimp-selection-save image)))))
  72.  
  73.   (let* ((selection-bounds (gimp-selection-bounds image))
  74.          (select-offset-x (cadr selection-bounds))
  75.          (select-offset-y (caddr selection-bounds))
  76.          (select-width (- (cadr (cddr selection-bounds)) select-offset-x))
  77.          (select-height (- (caddr (cddr selection-bounds)) select-offset-y))
  78.  
  79.          (shadow-width (+ select-width (* 2 shadow-blur)))
  80.          (shadow-height (+ select-height (* 2 shadow-blur)))
  81.  
  82.          (shadow-offset-x (- select-offset-x shadow-blur))
  83.          (shadow-offset-y (- select-offset-y shadow-blur)))
  84.  
  85.     (if (= allow-resize TRUE)
  86.         (let* ((new-image-width image-width)
  87.                (new-image-height image-height)
  88.                (image-offset-x 0)
  89.                (image-offset-y 0))
  90.  
  91.           (if (< (+ shadow-offset-x shadow-transl-x) 0)
  92.               (begin
  93.                 (set! image-offset-x (- 0 (+ shadow-offset-x
  94.                                              shadow-transl-x)))
  95.                 (set! shadow-offset-x (- 0 shadow-transl-x))
  96.                 (set! new-image-width (+ new-image-width image-offset-x))))
  97.  
  98.           (if (< (+ shadow-offset-y shadow-transl-y) 0)
  99.               (begin
  100.                 (set! image-offset-y (- 0 (+ shadow-offset-y
  101.                                              shadow-transl-y)))
  102.                 (set! shadow-offset-y (- 0 shadow-transl-y))
  103.                 (set! new-image-height (+ new-image-height image-offset-y))))
  104.  
  105.           (if (> (+ (+ shadow-width shadow-offset-x) shadow-transl-x)
  106.                  new-image-width)
  107.               (set! new-image-width
  108.                     (+ (+ shadow-width shadow-offset-x) shadow-transl-x)))
  109.  
  110.           (if (> (+ (+ shadow-height shadow-offset-y) shadow-transl-y)
  111.                  new-image-height)
  112.               (set! new-image-height
  113.                     (+ (+ shadow-height shadow-offset-y) shadow-transl-y)))
  114.  
  115.           (gimp-image-resize image
  116.                              new-image-width
  117.                              new-image-height
  118.                              image-offset-x
  119.                              image-offset-y)
  120.         )
  121.     )
  122.  
  123.     (set! shadow-layer (car (gimp-layer-new image
  124.                                             shadow-width
  125.                                             shadow-height
  126.                                             type
  127.                                             "Drop Shadow"
  128.                                             shadow-opacity
  129.                                             NORMAL-MODE)))
  130.     (gimp-image-add-layer image shadow-layer -1)
  131.     (gimp-layer-set-offsets shadow-layer
  132.                             shadow-offset-x
  133.                             shadow-offset-y))
  134.  
  135.   (gimp-drawable-fill shadow-layer TRANSPARENT-FILL)
  136.   (gimp-context-set-background shadow-color)
  137.   (gimp-edit-fill shadow-layer BACKGROUND-FILL)
  138.   (gimp-selection-none image)
  139.   (gimp-layer-set-lock-alpha shadow-layer FALSE)
  140.   (if (>= shadow-blur 1.0) (plug-in-gauss-rle RUN-NONINTERACTIVE
  141.                                               image
  142.                                               shadow-layer
  143.                                               shadow-blur
  144.                                               TRUE
  145.                                               TRUE))
  146.   (gimp-layer-translate shadow-layer shadow-transl-x shadow-transl-y)
  147.  
  148.   (if (= from-selection TRUE)
  149.       (begin
  150.         (gimp-selection-load active-selection)
  151.         (gimp-edit-clear shadow-layer)
  152.         (gimp-image-remove-channel image active-selection)))
  153.  
  154.   (if (and
  155.        (= (car (gimp-layer-is-floating-sel drawable)) 0)
  156.        (= from-selection FALSE))
  157.       (gimp-image-raise-layer image drawable))
  158.  
  159.   (gimp-image-set-active-layer image drawable)
  160.   (gimp-image-undo-group-end image)
  161.   (gimp-displays-flush)
  162.  
  163.   (gimp-context-pop)
  164.   )
  165. )
  166.  
  167. (script-fu-register "script-fu-drop-shadow"
  168.   _"_Drop Shadow..."
  169.   _"Add a drop shadow to the selected region (or alpha)"
  170.   "Sven Neumann <sven@gimp.org>"
  171.   "Sven Neumann"
  172.   "1999/12/21"
  173.   "RGB* GRAY*"
  174.   SF-IMAGE      "Image"           0
  175.   SF-DRAWABLE   "Drawable"        0
  176.   SF-ADJUSTMENT _"Offset X"       '(8 -4096 4096 1 10 0 1)
  177.   SF-ADJUSTMENT _"Offset Y"       '(8 -4096 4096 1 10 0 1)
  178.   SF-ADJUSTMENT _"Blur radius"    '(15 0 1024 1 10 0 1)
  179.   SF-COLOR      _"Color"          "black"
  180.   SF-ADJUSTMENT _"Opacity"        '(80 0 100 1 10 0 0)
  181.   SF-TOGGLE     _"Allow resizing" TRUE
  182. )
  183.  
  184. (script-fu-menu-register "script-fu-drop-shadow"
  185.                          "<Image>/Filters/Light and Shadow/Shadow")
  186.